<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use App\Models\District;
use App\Models\Property;
use App\Models\School;
use App\Models\SchoolDept;
use App\Models\SchoolSpeciality;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class DataProviderController extends Controller
{
    /**
     * 获取省份列表
     * @return array
     */
    public function getProvinceList()
    {
        return District::getProvinceList();
    }

    /**
     * @param $provinceId
     * @return mixed
     */
    public function getCityList($provinceId)
    {
        return District::getCityList($provinceId);
    }

    /**
     * @param $cityId
     * @return mixed
     */
    public function getSchoolList($cityId)
    {
        return School::getSchoolList($cityId);
    }

    /**
     * @param $schoolId
     * @return mixed
     */
    public function getDeptList($schoolId)
    {
        return SchoolDept::getDeptList($schoolId);
    }

    /**
     * @param $deptId
     * @return mixed
     */
    public function getSpecialityList($deptId)
    {
        return SchoolSpeciality::getSpecialityList($deptId);
    }


    /**
     * 重置前台用户的登录密码
     * @param $userId
     * @param Request $request
     * @return array|\Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    public function setUserPassword($userId, Request $request)
    {
        $user = User::findOrFail($userId);
        $password = $request->get('password', '');
        if ($password){
            $user->password = bcrypt($password);
            $user->save();
            return ['status' => 'success'];
        }else{
            return response(['password' => '请输入有效的密码'], 422);
        }
    }


    /**
     * 获取职称列表
     * @return array
     */
    public function getPositionTitleList()
    {
        return Property::where('type' , '=' , '职称')->select('index', 'value')->get()->toArray();
    }

}
